<%@ page import="com.hrm.dto.Envelope" %>
<%@ page import="com.hrm.entity.SalaryEntity" %>
<%@ page import="java.util.Date" %>
<%@ page import="com.hrm.entity.EmployeeEntity" %><%--
  Created by IntelliJ IDEA.
  User: zekdot
  Date: 20-3-4
  Time: 下午2:51
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/table.css">
    <link href="${pageContext.request.contextPath}/css/main.css" rel="stylesheet" type="text/css">
    <script src="${pageContext.request.contextPath}/js/jquery.min.js"></script>
</head>
<body>
<%
    Envelope envelope = (Envelope) request.getAttribute("param");
//    System.out.println(envelope);
    SalaryEntity salaryEntity = (SalaryEntity) envelope.getObj();
    EmployeeEntity employeeEntity = (EmployeeEntity) session.getAttribute("user");
%>

<div class="div_form">

    <h1 class="h1_style"><i class="i_h1"></i>薪水情况</h1>
    <label>
        <select id="year" style="width: 20%;margin-top:30px">
            <option selected>2020</option>
            <option>2019</option>
            <option>2018</option>
            <option>2017</option>
        </select>
        <select id="month" style="width: 20%;margin-top:30px">
            <%
                int month = new Date().getMonth();
                for(int i=0;i<12;i++){
                    String monthStr = String.format("%02d",i+1);
            %>
            <option <%=month==i?"selected":""%>><%=monthStr%></option>
            <%
                }
            %>
        </select>
    </label>
    <form id="form_demo" >
        <p class="form_p"><label class="form_label">基本工资：</label>
            <input type="text" id="base" class="form_input readonly" readonly="readonly"
                   value="<%=salaryEntity.getBase()%>">
        </p>
        <p class="form_p"><label class="form_label">奖金：</label>
            <input type="text" id="bonus" class="form_input readonly" readonly="readonly"
                   value="<%=salaryEntity.getBonus()%>">
        </p>
        <p class="form_p"><label class="form_label">扣款金额：</label>
            <input type="text" id="deduct" class="form_input readonly" readonly="readonly"
                   value="<%=salaryEntity.getDeduct()%>">
        </p>
        <p class="form_p"><label class="form_label">实发金额：</label>
            <input type="text" id="real" class="form_input readonly" readonly="readonly"
                   value="<%=salaryEntity.getBase()+salaryEntity.getBonus()-salaryEntity.getDeduct()%>">
        </p>
        <p class="form_p"><label class="form_label">考核等级：</label>
            <input type="text" id="comLevel" class="form_input readonly" readonly="readonly"
                   value="<%=salaryEntity.getComLevel()%>">
        </p>
    </form>
</div>


<div style="padding:5px 20px">

    <br>


    <script>
        // function calcReal() {
        //     var base = eval('(' + $('#base').val() + ')');
        //     var bonus = eval('(' + $('#bonus').val() + ')');
        //     var deduct = eval('(' + $('#deduct').val() + ')');
        //     $('#real').val(base + bonus - deduct);
        // }
        function updateData(){
            var year = $('#year').val(),month = $('#month').val();
            var id = '<%=employeeEntity.getId()%>';
            var data = {'id':id,'year':year,'month':month};
            $.post('${pageContext.request.contextPath}/employee/salary',data,function (str) {
                // alert(str);
                var res = eval('(' + str + ')');
                if(res.code != 0){
                    alert(res.message);
                }else{
                    res = res.object;
                    $('#base').val(res.base);
                    $('#bonus').val(res.bonus);
                    $('#deduct').val(res.deduct);
                    $('#real').val(res.base + res.bonus - res.deduct);
                    $('#comLevel').val(res.comLevel);
                }
            });
        }
        $('#year').on('change',updateData);
        $('#month').on('change',updateData);
    </script>
</div>
</body>
</html>
